package com.whg.demo.biz;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @Author whg
 * @create 2023/6/16 18:09
 * @description：
 */
public class TestExcel3 {

    public static void main(String[] args) throws Exception{

        //单据模板路径
        String templatePath = "D:\\home\\project_two\\excel\\单据模板.xlsm";
        FileInputStream fis = new FileInputStream(templatePath);
        //生成的单据文件路径
        String filePath = "D:\\home\\project_two\\excel\\单据模板2.xlsm";
        File targetFile = new File(filePath);
        if (!targetFile.exists()){
            targetFile.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(filePath);
        //创建工作表
        XSSFWorkbook workbook = new XSSFWorkbook(fis);
        XSSFSheet sheet = workbook.getSheetAt(0);
        sheet.getRow(0).getCell(5).setCellValue("LC0002");
        //写入文件输出流
        workbook.write(fos);
        workbook.close();
        fos.close();
    }
}
